package org.ourguy.mymoviesandshows;


import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

public class ShowActivity extends TabActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		Resources res = getResources(); // Resource object to get Drawables
		TabHost tabHost = getTabHost();  // The activity TabHost
		TabHost.TabSpec spec;  // Reusable TabSpec for each tab
		Intent intent;  // Reusable Intent for each tab
		
		Bundle bundle = getIntent().getExtras();

		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, ShowGeneralInfoActivity.class);
		if(bundle != null)
			intent.putExtras(bundle);
		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("generalInfo").setIndicator("General Info",
						  res.getDrawable(R.drawable.ic_heart_medium))
					  .setContent(intent);
		tabHost.addTab(spec);
		
		intent = new Intent().setClass(this, ShowSeasonsActivity.class);
		if(bundle != null)
			intent.putExtras(bundle);
		spec = tabHost.newTabSpec("seasons").setIndicator("Seasons",
						  res.getDrawable(R.drawable.ic_chart_medium))
					  .setContent(intent);
		tabHost.addTab(spec);
		
		tabHost.setCurrentTab(0);
	}
	
	 @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		  MenuInflater inflater = getMenuInflater();
		  inflater.inflate(R.menu.main_menu, menu);
		  return true;
	}
	 
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.menuTrackingList:
		{
			Intent intent = new Intent().setClass(getApplicationContext(),
					MyMoviesAndShowsActivity.class);
			intent.putExtra("tab", 0);
			this.startActivity(intent);
			return true;
		}
		case R.id.menuSchedule:
		{
			Intent intent = new Intent().setClass(getApplicationContext(),
					MyMoviesAndShowsActivity.class);
			intent.putExtra("tab", 2);
			this.startActivity(intent);
			return true;
		}
		case R.id.menuAbout:
        {
        	Intent intent = new Intent().setClass(getApplicationContext(), AboutActivity.class);
        	this.startActivity(intent);
        	return true;
        }
        case R.id.menuSearch:
        {
        	Intent intent = new Intent().setClass(getApplicationContext(), SearchActivity.class);
        	this.startActivity(intent);
        	return true;
        }
		default:
			return super.onOptionsItemSelected(item);
		}
	}

}
